package common.server.redis.jedis.pool;


import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @author Administrator
 * @version [版本号, 2017/11/22 0022]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class JedisPoolExt {


    /**
     *
     */
    private final HostAndPort hostAndPort;

    /**
     *
     */
    private final JedisPool jedisPool;

    public JedisPoolExt(GenericObjectPoolConfig poolConfig, String host, int port, int connectionTimeout, int soTimeout, String password, int defaultDatabase, String clientName) {
        this.hostAndPort = new HostAndPort(host, port);
        this.jedisPool = new JedisPool(poolConfig, host, port, connectionTimeout, password, defaultDatabase, clientName);
    }

    /**
     *
     * @return
     */
    public Jedis getResource() {
        return jedisPool.getResource();
    }

    /**
     *
     */
    public void close() {
        jedisPool.close();
    }

    /**
     * 获取 jedisPool
     * @return 返回 jedisPool
     */
    public JedisPool getJedisPool() {
        return jedisPool;
    }

    /**
     * 获取 hostAndPort
     * @return 返回 hostAndPort
     */
    public HostAndPort getHostAndPort() {
        return hostAndPort;
    }
}
